home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Languages
/
Yerk 3.6.7
/
yerk 367
/
System source
/
PathList
< prev
next >
Wrap
Text File
|
1994-11-29
|
6KB
|
157 lines
\ 7/04/86 cdn A general class to maintain lists of paths
\ 7/09/86 cdn Added getPtxt
\ 9/26/86 rfd added GET:
\ 12/29/90 rfl now part of sarray
\ 1/02/90 rfl added check for >255 in (count)
\ 4/10/91 rfl fixed to: with @sarray change to return offset
\ 11/29/94 rfl fixed small bug in (count) where sometimes size=n+1
\ Class Sarray - string array
\ used just like an array, but with arbitrary length elements.
\ Each element is a pascal string.
\ 11.26.90 rfl cleared size with new:
\ 11.28.90 rfl fixed at: sarray by get: size 1-
hex
\ limits checked at high level
create @Sarray ( ind startAddr -- addr len offset )
4281 w, \ clr.l d1
205F w, \ movea.l (sp)+,a0 \ get start addr
2248 w, \ movea.l a0,a1 \ make a copy
201F w, \ move.l (sp)+,d0 \ get index
D1CB w, \ adda.l a3,a0 \ convert to abs addr
1218 w, \ loop move.b (a0)+,d1 \ get len
5380 w, \ subq.l #1,d0 \ dec index
0C80 w, ffffffff , \ cmpi.l #-1,d0 \ time to get out
6700 w, 0008 w, \ beq out
D1C1 w, \ adda.l d1,a0 \ go to next index
6000 w, ffee w, \ bra loop
91CB w, \ out suba.l a3,a0 \ get rel addr
2F08 w, \ move.l a0,-(sp)
2F01 w, \ move.l d1,-(sp)
91c9 w, \ suba.l a1,a0 \ get offset from start
5388 w, \ subq #1,a0 \ less one
2f08 w, \ move.l a0,-(sp)
next,
\ counts the number of items in an sarray format
create SCount ( addr len -- n)
4281 w, \ clr.l d1
241F w, \ move.l (sp)+,d2
2057 w, \ movea.l (sp),a0
D1CB w, \ adda.l a3,a0
2248 w, \ movea.l a0,a1
D3C2 w, \ adda.l d2,a1 \ stop addr
1010 w, \ loop move.b (a0),d0
D1C0 w, \ adda.l d0,a0
5288 w, \ addq #1,a0
5281 w, \ addq #1,d1 \ inc counter
B3C8 w, \ cmp.l a0,a1 \ time to stop
6E00 w, fff4 w, \ bgt loop
2E81 w, \ move.l d1,(sp)
next,
\ If the list is a list of items separated by a delimeter, then this word
\ searches through list, finds delimeters and replaces with the count to
\ bring it to sarray format. Proceeds to end of string with or without a delimeter there
create (count) \ ( addr len delimeter -- count)
4282 w, \ clr.l d2 \ count
261F w, \ move.l (sp)+,d3 \ char
2C1F w, \ move.l (sp)+,d6 \ len
2057 w, \ movea.l (sp),a0 \ addr
D1CB w, \ adda.l a3,a0
5288 w, \ addq #1,a0 \ start after first count byte
5386 w, \ subq.l #1,d6 \ and therefore one less to go
2248 w, \ movea.l a0,a1 \ store start
B618 w, \ start cmp.b (a0)+,d3 \ compare first char with delimeter
6600 w, 0022 w, \ bne noadd \ if no match, continue
5282 w, \ addq #1,d2 \ else, increment count
2008 w, \ move.l a0,d0
9089 w, \ sub.l a1,d0
5380 w, \ subq #1,d0
b07c w, 00ff w, \ cpi.w #255,d0 \ make sure element is <255
6d00 w, 000c w, \ blt ok
2ebc w, ffffffff , \ move.l #-1,(sp) \ put -1 on stack if illegal
6000 w, 0010 w, \ bra out
1340 w, ffff w, \ move.b d0,-1(a1) \ get size and put into location
2248 w, \ movea.l a0,a1 \ get new size location
5386 w, \ noadd subq.l #1,d6 \ one less to go
6E00 w, ffd6 w, \ bgt start \ continue until zero
2E82 w, \ move.l d2,(sp) \ store count on stack
\ out
next,
decimal
\ class of ordered-col of strings. format is str255str255.....str255
:CLASS sarray <super string
var size \ # of elements in array
int delimeter
\ clearing size prevents problems when image is saved with size set nonzero
:M new: new: super clear: size ;M
\ returns # of elements
:M limit: ( -- n) get: size ;M
:M putLimit: ( n --) put: size ;M
:M putChar: ( n --) put: delimeter ;M
\ if want to go faster, remove range checking
:M at: ( ind -- addr len) dup get: size 1- > >r dup 0< r> or classerr" 129 ptr: self @sarray
put: offset ;M
:M ^elem: ( ind -- addr) at: self drop 1- ;M
:M print: limit: self 0 DO i . i at: self type cr ?pause LOOP ;M
:M indexOf: { addr len \ flag -- ind t or f }
limit: self 0 false -> flag
DO addr len i at: self s= IF i true -> flag LEAVE THEN LOOP
flag ;M
:M remove: ( ind -- )
^elem: self dup ptr: self - put: offset
dup c@ 1+ delete: super -1 +: size ;M
:M to: { addr len ind -- } ind at: self
swap 1- swap 1+ addr len str255 -base len 1+ replace: self ;M
:M add: { addr len -- } len 255 > classerr" 135
len +: super addr len add: super 1 +: size ;M
:M clear: clear: super clear: size ;M
:M =: { anotherSarray -- } getState: super lock: self
get: self put: anotherSarray setState: self
limit: self putLimit: anotherSarray ;M
\ given the addr len of an sarray format list on the stack, put into an object
:M put: ( addr len --) put: super get: self scount put: size ;M
\ use for delimeted string, thus far uncounted. If already in format, don't use
:M count: get: self + 1- c@ get: delimeter <>
IF get: delimeter +: self THEN
start: self pad 1 insert: self
get: self get: delimeter (count) put: size
size: self 1- setsize: self get: size 0< classerr" 135 ;M
\ use instead of put:
\ assuming the data is delimited by some character, as in the following format:
\ dddd|dd|dddd|dddd|
\ where d is data and | is the delimeter - last element doesn't need trailing delimeter
\ modify to the sarray format.
:M place: ( addr len --) put: super count: self ;M
;CLASS
\ ( addr len -- ) Setup path string from text file
: getPtxt new: loadFile name: topFile
OpenReadOnly: topFile ?error 179
path IF release: path dispose> path THEN
heap> sarray -> path new: path 13 putChar: path
topfile size: topfile read: path drop
count: path
remove: loadFile ;